package com.cn.yz.springboot.interceptor;

import java.io.IOException;
import java.util.List;
import java.util.Map.Entry;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.MultivaluedMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

public class JerseyFilter implements ContainerRequestFilter {
	
	Logger logger = LoggerFactory.getLogger(JerseyFilter.class);

	@Override
	public void filter(ContainerRequestContext request) throws IOException {
		logger.info("JerseyFilter.filter---->");
		String url = request.getUriInfo().getPath();
		//如果没有url，则直接访问
		if(StringUtils.isEmpty(url)){
			return;
		}
		//排除登录接口
//		if("login".equalsIgnoreCase(url)){
//			return;
//		}
		
		String language = request.getHeaderString("Accept-Language");
		logger.info("language--------->"+language);
		String token = request.getHeaderString("Accept-Token");
		MultivaluedMap<String, String> map = request.getHeaders();
		for(Entry<String, List<String>> e : map.entrySet()){
			logger.info(e.getKey()+":"+e.getValue());
		}
		logger.info("token--------->"+token);
		
	}

}
